home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MPW_TOOL
/
TOOLS
/
TOOLS_WI
/
ICON_8
/
MEMMON_F
/
MMMETA.C
< prev
next >
Wrap
Text File
|
1990-03-02
|
4KB
|
166 lines
/*
* mmmeta.c: batch mode metafile(5) translator.
*/
#include "memmon.h"
hidden novalue mffhex Params((unsigned char *p, int x, int y, int w, int h));
hidden novalue mffcolor Params((int c, char *text));
#define CharHeight (textrow / 2) /* height of a text char */
#define CharBase (textrow / 5) /* offset to baseline within text box */
#define CharProp ((150 * width) / (TextLength * CharHeight))
/* proportionality */
static char hexo[MapSize][4]; /* color map entries as 3 hex chars */
/*
* devsetup() - set globals to device-dependent values.
*/
novalue devsetup()
{
granularity = 4;
width = 912;
height = 630;
textrow = 20;
textsep = 2;
memrow = 20;
batchmode = 1;
}
/*
* devinit() - initialize output file.
*/
novalue devinit()
{
char time_buf[26];
getctime(time_buf);
printf("%% Icon MemMon snapshots\n");
if (title)
printf("%% %s\n", title);
printf("%% %s", time_buf);
printf("\n");
printf("1 metafile\n");
}
/*
* batbegin() - prepare to write an image.
*/
novalue batbegin()
{
int i;
for (i = 0; i < MapSize; i++) { /* init hex color map */
hexo[i][0] = "0123456789ABCDEF"[cmap[i].red>>4];
hexo[i][1] = "0123456789ABCDEF"[cmap[i].green>>4];
hexo[i][2] = "0123456789ABCDEF"[cmap[i].blue>>4];
}
printf("\n%d %d ", width-1, height-1);
mffcolor(C_Background, "init\n"); /* start new page/frame/etc. */
if (textrow > 0)
printf("%d %d 100 (Helvetica) font\n", CharHeight, CharProp);
}
/*
* battext(s, row, col, fg, bg) - output text string.
*/
novalue battext(s, row, col, fg, bg)
char *s;
int row, col, fg, bg;
{
float charwidth;
int x, xx, y;
charwidth = (float)width / (float)TextLength;
x = charwidth * col;
xx = charwidth * (col + strlen(s) + 1);
y = height - (row + 1) * textrow + 1;
mffcolor(bg, "color ");
printf("%d %d begin %d %d line %d %d line %d %d line fill\n",
x, y, x, y + textrow - 2, xx - 2, y + textrow - 2, xx - 2, y);
x += charwidth / 2;
y += CharBase;
mffcolor(fg, "color ");
printf("%d %d ", x, y);
pstext(s);
printf(" text\n");
}
/*
* batmem(mbuf) - output memory image.
*/
novalue batmem(mbuf)
unsigned char mbuf[];
{
word n;
int w, y;
y = memheight;
n = mempixels;
while (n > 0 && (y -= memrow) >= 0) {
w = (n > width) ? (word)width : n;
/* the cast above avoids a Lightspeed C 2.0 bug */
mffhex(mbuf, 0, y, w, memrow-1);
mbuf += w;
n -= w;
}
}
/*
* batterm() - terminate entire run. (Nothing to do.)
*/
novalue batterm()
{
}
/*
* mffcolor(c, text) - output mff color spec, then the text.
*/
static novalue mffcolor(c, text)
int c;
char *text;
{
printf("%3d %3d %3d %s", cmap[c].red, cmap[c].green, cmap[c].blue, text);
}
/*
* mffhex(buf, x, y, w, h) - output one line of raster data in hex.
*/
static novalue mffhex(buf, x, y, w, h)
unsigned char *buf;
int x, y, w, h;
{
register int i;
register char *o;
register unsigned char *p, *q;
/*
* Check for a line that's all the same color, and output more compactly.
*/
p = buf;
i = *p;
for (q = p + w; q > p && *--q == i; )
;
if (q == p) {
printf("%d %d %d %d 1 1 -4 raster\n%s0\n", x, y, w, h, hexo[i]);
return;
}
/*
* Optimization failed. Output line in detail.
*/
printf("%d %d %d %d %d 1 -4 raster", x, y, w, h, w);
for (i = 0; i < w; i++) {
if ((i & 31) == 0)
putchar('\n');
o = hexo[*p++];
putchar(*o++); /* red */
putchar(*o++); /* green */
putchar(*o); /* blue */
}
if (w % 2)
putchar('0'); /* must have an even number of hex digits per raster */
putchar('\n');
}